package com.tyqx.hashchainbiz.controller.supplier;

import com.tyqx.hashchainbean.module.ProducePlan;
import com.tyqx.hashchainbean.module.ShippingInfo;
import com.tyqx.hashchainbean.vo.*;
import com.tyqx.hashchainbiz.service.ProducePlanService;
import com.tyqx.hashchainbiz.service.QueryDonateService;
import com.tyqx.hashchainbiz.service.TrackDonateService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "生产计划")
@RestController
@RequestMapping("/producePlan")
@CrossOrigin
public class ProducePlanController {

    @Resource
    private ProducePlanService producePlanService;

    @RequestMapping(value="/saveProducePlan", method = RequestMethod.POST)
    @ResponseBody
    public String saveProducePlan(@RequestBody ProducePlanVO producePlanVO) throws Exception {

        String msg="";
        ProducePlan producePlan=new ProducePlan();
        producePlan.setProduceName(producePlanVO.getProduceName());
        producePlan.setProduceNum(producePlanVO.getProduceNum());
        producePlan.setProducePeriod(producePlanVO.getProducePeriod());
        producePlan.setProduceTime(producePlanVO.getProduceTime());
        producePlan.setProduceUnit(producePlanVO.getProduceUnit());
        producePlan.setUserName(producePlanVO.getUserName());
        if(producePlanService.producePlan(producePlan)>0){
            msg="添加生产计划成功";
        }else{
            msg="添加生产计划失败";
        }
        return msg;
    }

    @RequestMapping(value="/getProducePlanById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProducePlan> getProducePlanById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return producePlanService.getProducePlanById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getProducePlanByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProducePlan> getProducePlanByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return producePlanService.getProducePlanByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
